/**
 * 设备维修保养记录查询
 * @author yuan_rz
 * @date 2019/12/23
 */
define(function () {

    var self,
        doc = document,
        app = win.app,
        layui = win.layui,
        element,
        table,
        table_param = {},
        cols = [[
            {field: 'ROW_ID', width: 80, title: '序号'}
            , {
                field: 'MMRG003', width: 150, title: '设备名称', sort: true, hide: true,
                search: 'default', searchOpts: {icon: true}
            }
            , {field: 'DEVICE_NAME', width: 150, title: '设备名称', sort: true}
            , {
                field: 'MMRG004', width: 150, title: '序列号', sort: true,
                search: 'default', searchOpts: {icon: true}
            }
            , {
                field: 'MMRA001', width: 150, title: '客户名称', sort: true, hide: true,
                search: 'default', searchOpts: {icon: true}
            }
            , {field: 'CUSTOMER_NAME', width: 150, title: '客户名称', sort: true}
            , {
                field: 'MMRG010', width: 150, title: '问题描述', sort: true,
                search: 'default'
            }
            , {field: 'MMRGDOCDATE', width: 150, title: '维修日期', sort: true}
            , {
                field: 'MMRG005', width: 150, title: '维修人员', sort: true, hide: true,
                search: 'default', searchOpts: {icon: true}
            }
            , {field: 'USER_NAME', width: 150, title: '维修人员', sort: true}
            , {field: 'ORG_NAME', width: 150, title: '维修部门', sort: true}
            , {
                field: 'MMRQ001', width: 150, title: '故障内容', sort: true,
                search: 'default', searchOpts: {icon: true}
            }
            , {field: 'MMRG102', width: 150, title: '维修内容', sort: true}
        ]],
        editArea = ['720px', '360px'],
        moduleName = '设备维修保养记录'
    ;

    var gwai741 = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwai741',
                _searchs: [{
                    id: 'gwai741', tableId: 'gwai741_table', datas: cols[0]
                }],
                _loadTplsFull: [{
                    dom: 'gwai741_edit', tpl: 'gwai741_edit'
                }, {
                    dom: 'common_open_window', tpl: 'common/_open_window'
                }]
            }, win);
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'gwai741_table'),
                    url: g_ctxPath + 'crm/gwai741/getListData',
                    title: moduleName + '表',
                    method: 'post',
                    id: 'gwai741_table',
                    initSort: {field: 'DEVICE_NAME', type: 'ASC'},
                    size: _layuiConfig.ui_size,
                    autoSort: false, //禁用前端自动排序
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter'],
                    height: 'full',
                    cols: cols,
                    loading: true,
                    page: true,
                    where: '',
                    done: function (res, curr, count) {

                    }
                });

                //监听行双击事件
                table.on('rowDouble(gwai741_table)', function (obj) {
                    self._openTplFull({
                        tag: 'gwai741_edit',
                        tagData: {
                            obj: obj
                        },
                        index: 0,
                        openOpts: {
                            title: moduleName + '详情',
                            area: editArea
                        }
                    });
                });

            });
        },

        reloadTableCurr: function () {
            self._reloadTable({id: 'gwai741_table', where: table_param});
        },
        _ready: function () {
            this._super({
                vue: [{
                    el: '#page',
                    data: '',
                    searchId: 'gwai741',
                    methods: {
                        handleIconClick: function (field) {
                            var vue = this;
                            if (field == 'MMRG003' || field == 'MMRG004' || field == 'MMRA001') {//设备名称
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'cq_mmra001_1',
                                            columnList: [
                                                {label: '设备编号', prop: 'MMRA002', width: '150'},
                                                {label: '设备名称', prop: 'MMRA004', width: '150'},
                                                {label: '序列号', prop: 'MMRA003', width: '150'},
                                                {label: '客户编号', prop: 'MMRA001', width: '150'}
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.MMRG003 = data.MMRA002;
                                            vue.isearch.fields.MMRG004 = data.MMRA003;
                                            vue.isearch.fields.MMRA001 = data.MMRA001;
                                        }
                                    },
                                    index: 1,
                                    openOpts: {
                                        title: '选择设备',
                                        area: ['600px', '470px']
                                    }
                                });
                            } else if (field == 'MMRG005') {//维修人员
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysuser_id',
                                            columnList: [
                                                {label: '维修人员ID', prop: 'ID', width: '150'},
                                                {label: '维修人员账号', prop: 'ACCOUNT', width: '150'},
                                                {label: '维修人员名称', prop: 'NAME', width: '150'}
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.MMRG005 = data.ID;
                                        }
                                    },
                                    index: 1,
                                    openOpts: {
                                        title: '选择维修人员',
                                        area: ['600px', '465px']
                                    }
                                });
                            } else if (field == 'MMRQ001') { //故障内容
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_mmrl001',
                                            columnList: [
                                                {label: '故障编号', prop: 'MMRL001', width: '150'},
                                                {label: '说明', prop: 'MMRLL003', width: '150'},
                                                {label: '助记码', prop: 'MMRLL004', width: '150'}
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.MMRQ001 = data.MMRL001;
                                        }
                                    },
                                    index: 1,
                                    openOpts: {
                                        title: '选择故障',
                                        area: ['600px', '465px']
                                    }
                                });
                            }
                        }
                    }
                }]
            });
            self.initTable();
        },
        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element = layui.element;
            });
        }
    });

    return new gwai741();

});